<template>
	<view>
		<text>{{text}}</text>
	</view>
</template>

<script>
	export default {
		props: ["item"],
		
		data() {
			return {
				text:'',
				val:{},
				intervalId: null
			}
		},
		mounted() {
			this.val = this.item
			if(this.val.dev_qiang_status=='是'){
				this.text = '查看充电';
			}else if(this.val.dev_qiang_status=='否'){
				this.text = '未插枪';
			}else{
				this.text = '充电启动中';
			}
			
			this.lookat();
		},
		beforeDestroy() { // 对于 Vue 2 组件
		    this.clearTimer();
		},
		methods: {
			lookat(){
				var that = this
				var id = this.val.id
				that.order(id)
				
				this.intervalId = setInterval(function(){
					that.order(id)
				},5000)
			},
			clearTimer() {
			  if (this.intervalId) {
				clearInterval(this.intervalId);
				this.intervalId = null; // 清除引用，帮助垃圾回收
			  }
			},
			async order(id){
				var that = this
				const res = await this.http("post", "/api/order/info2", {
					id: id,
				})
				this.val = res.data
				if(this.val.dev_qiang_status=='是'){
					this.text = '查看充电';
				}else if(this.val.dev_qiang_status=='否'){
					this.text = '未插枪';
				}else{
					this.text = '充电启动中';
				}
			},
		}
	}
</script>

<style>

</style>
